package com.ai.zhly.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.ai.dmc.index.base.impl.base.BaseServiceImpl;
import com.ai.dmc.index.base.sequence.SequenceGenerator;
import com.ai.dmc.index.common.InitParam;
import com.ai.dmc.index.common.bean.AnalysisBean;
import com.ai.dmc.index.common.bean.AreaBean;
import com.ai.dmc.index.common.bean.CommonBaseBean;
import com.ai.dmc.index.common.bean.ExportBean;
import com.ai.dmc.index.common.cache.AreaCache;
import com.ai.dmc.index.common.exception.BusinessException;
import com.ai.dmc.index.common.util.BasicKMeans;
import com.ai.dmc.index.common.util.DateUtil;
import com.ai.dmc.utils.json.JsonUtil;
import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 
 * @Title: MapDataImpl.java
 * @Description: 家装宽带展示层service
 * @author xueyf3
 * @date 2016年5月23日 下午4:22:54 Copyright：Copyright (c) 2016
 *       Company：北京亚信智慧数据科技有限公司
 * @version V1.0
 */
@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
public class AnalysisServiceImpl extends BaseServiceImpl
		implements IAnalysisService {
	// 定义对应Mapper文件的命名空间
	private static final String NAMESPACE = "Analysis.";

	public static Logger log = LoggerFactory
			.getServiceLog(AnalysisServiceImpl.class);

	private SequenceGenerator sequenceGenerator;

	private ICommonService commonService;

	public void setSequenceGenerator(SequenceGenerator sequenceGenerator) {
		this.sequenceGenerator = sequenceGenerator;
	}

	public void setCommonService(ICommonService commonService) {
		this.commonService = commonService;
	}

	@Override
	public void queryCityList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		String userId = inputObject.getParams().get("userId");
		// List<AnalysisBean> rset = new ArrayList<AnalysisBean>();
		List<AnalysisBean> list = this.getBaseDao().queryForList(
				NAMESPACE + "queryCityList", inputObject.getParams(),
				AnalysisBean.class);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<JSONObject> rl = new ArrayList<JSONObject>();
		boolean provFlag = false;// 数据权限是否为全省的标识
		boolean isAdmin = inputObject.getParams().get("isAdmin") == null ? false
				: Boolean.valueOf(inputObject.getParams().get("isAdmin"));
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		for (int i = 0; i < list.size(); i++) {
			String cityId = list.get(i).getCity_id();
			for (String aId : allList) {
				if (cityId.startsWith(aId)) {
					// rset.add(list.get(i));
					String city_id = list.get(i).getCity_id();
					String city_name = list.get(i).getCity_name();
					// String core_longitude=list.get(i).getCore_longitude();
					// String core_latitude=list.get(i).getCore_latitude();
					JSONObject tmpObj = new JSONObject();
					tmpObj.put("city_id", city_id);
					tmpObj.put("city_name", city_name);
					// tmpObj.put("core_longitude", core_longitude);
					// tmpObj.put("core_latitude", core_latitude);
					rl.add(tmpObj);
					break;
				}
			}
		}
		if (InitParam.DEPLOY_PROVINCE_ID
				.equals(inputObject.getParams().get("areaId"))) {
			provFlag = true;
		}
		if (provFlag || isAdmin) {
			// if (rset.size() > 1) {
			// AnalysisBean bean = new AnalysisBean();
			// bean.setCity_id("");
			// bean.setCity_name("全省");
			// rset.add(0, bean);
			JSONObject tmpObj = new JSONObject();
			tmpObj.put("city_id", "");
			tmpObj.put("city_name", InitParam.TOP_AREA_NAME);
			rl.add(0, tmpObj);
		}

		resultMap.put("cityList", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}

	@Override
	public void queryRegionTypleList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		List<AnalysisBean> list = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionTypleList", inputObject.getParams(),
				AnalysisBean.class);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<JSONObject> rl = new ArrayList<JSONObject>();

		AnalysisBean bean = new AnalysisBean();
		bean.setRegion_type("");
		bean.setRegion_type_name("全部");
		list.add(0, bean);

		for (int i = 0; i < list.size(); i++) {
			String region_type = list.get(i).getRegion_type();
			String region_type_name = list.get(i).getRegion_type_name();
			JSONObject tmpObj = new JSONObject();
			tmpObj.put("region_type", region_type);
			tmpObj.put("region_type_name", region_type_name);
			rl.add(tmpObj);
		}

		resultMap.put("regionTypeList",
				null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}

	@Override
	public void queryRegionList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		String userId = inputObject.getParams().get("userId");
		List<AnalysisBean> list = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionList", inputObject.getParams(),
				AnalysisBean.class);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<JSONObject> rl = new ArrayList<JSONObject>();
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		for (int i = 0; i < list.size(); i++) {
			String regionId = list.get(i).getRegion_id();
			for (String aId : allList) {
				if (regionId.startsWith(aId)) {
					String city_id = list.get(i).getCity_id();
					String region_id = list.get(i).getRegion_id();
					String region_name = list.get(i).getRegion_name();

					JSONObject tmpObj = new JSONObject();
					tmpObj.put("city_id", city_id);
					tmpObj.put("region_id", region_id);
					tmpObj.put("region_name", region_name);
					rl.add(tmpObj);
					break;
				}
			}
		}
		if (rl.size() > 1) {
			JSONObject tmpObj = new JSONObject();
			tmpObj.put("city_id", "");
			tmpObj.put("region_id", "");
			tmpObj.put("region_name", "全部");
			rl.add(0, tmpObj);
		}

		resultMap.put("regionList", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	@Override
	public void queryTouristSourceList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// Map<String, String> params = inputObject.getParams();// 获取查询条件信息
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime");
		if (endTime == null || endTime.equals("")) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_vst_src_d");
			inputObject.getParams().put("endTime", endTime);
		}

		String dateFormat = "";
		String startTime = inputObject.getParams().get("startTime");
		if (startTime == null || startTime.equals("")) { // 当日期为空时，设置默认日期
			if (endTime.length() == 8) {
				dateFormat = "yyyyMMdd";
				startTime = DateUtil.getInstance().getXDay(endTime, dateFormat,
						-6); // 前2周
			} else {
				dateFormat = "yyyyMM";
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						dateFormat, -12); // 前12个月
			}

			inputObject.getParams().put("startTime", startTime);
		}
		// 查询
		List<AnalysisBean> provlist = this.getBaseDao().queryForList(
				NAMESPACE + "queryProvRegionList", inputObject.getParams(),
				AnalysisBean.class);
		List<AnalysisBean> citylist = this.getBaseDao().queryForList(
				NAMESPACE + "queryCityRegionList", inputObject.getParams(),
				AnalysisBean.class);
		List<CommonBaseBean> fornlists = this.getBaseDao().queryForList(
				NAMESPACE + "queryFornRegionList", inputObject.getParams(),
				CommonBaseBean.class);
		//处理commonbasebean里取得的境外游客数据
		List<AnalysisBean> fornlist=new ArrayList<AnalysisBean>(); 
		for(CommonBaseBean bean :fornlists){
			AnalysisBean analy=new AnalysisBean();
			analy.setProv_name(bean.getQuery_value1());
			analy.setVst_person_cnts(bean.getQuery_value2());
			fornlist.add(analy);
		}
		List<AnalysisBean> pieData = this.getBaseDao().queryForList(
				NAMESPACE + "queryThreeClassifyList", inputObject.getParams(),
				AnalysisBean.class);

		// 按排序分层次
		double[] provPersonCnt = new double[provlist.size()];
		int n = 0;
		for (AnalysisBean bean : provlist) {
			provPersonCnt[n++] = Double.parseDouble(bean.getVst_person_cnts());
		}
		List<Double> provEdgeInfo = BasicKMeans.getGroupEdgeValue(provPersonCnt,
				5);

		double[] cityPersonCnt = new double[citylist.size()];
		n = 0;
		for (AnalysisBean bean : citylist) {
			cityPersonCnt[n++] = Double.parseDouble(bean.getVst_person_cnts());
		}
		List<Double> cityEdgeInfo = BasicKMeans.getGroupEdgeValue(cityPersonCnt,
				5);
		
		double[] fornPersonCnt = new double[fornlist.size()];
		n = 0;
		for (AnalysisBean bean : fornlist) {
			fornPersonCnt[n++] = Double.parseDouble(bean.getVst_person_cnts());
		}
		List<Double> fornEdgeInfo = BasicKMeans.getGroupEdgeValue(fornPersonCnt,
				5);

		// 框架可以自动转基本类型为json；对象自动转json，value为对象地址。所以需要提前转换
		JSONArray provlistJson = JSONArray.fromObject(provlist);
		JSONArray citylistJson = JSONArray.fromObject(citylist);
		JSONArray fornlistJson = JSONArray.fromObject(fornlist);
		JSONArray pieDataJson = JSONArray.fromObject(pieData);
		JSONArray provEdgeJson = JSONArray.fromObject(provEdgeInfo);
		JSONArray cityEdgeJson = JSONArray.fromObject(cityEdgeInfo);
		JSONArray fornEdgeJson = JSONArray.fromObject(fornEdgeInfo);
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		//
		// this.appendObject("startTime", startTime);
		// this.appendObject("endTime", endtTime);
		// this.appendObject("provList", provlistJson);
		// this.appendObject("provEdgeInfo", provEdgeJson);
		// this.appendObject("cityList", citylistJson);
		// this.appendObject("cityEdgeInfo", cityEdgeJson);
		// this.appendObject("pieData", pieDataJson);
		//
		//
		// List<AnalysisBean> list = this.getBaseDao().queryForList(
		// NAMESPACE + "queryRegionList",
		// inputObject.getParams(),AnalysisBean.class);
		// Map<String, Object> resultMap = new HashMap<String, Object>();
		// List<JSONObject> rl = new ArrayList<JSONObject>();
		// // 数据权限
		// Map<String, List<String>> scopeMap =
		// commonService.queryUserScope(userId);
		// List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		// for (int i = 0; i < list.size(); i++) {
		// String regionId = list.get(i).getRegion_id();
		// for (String aId : allList) {
		// if (regionId.startsWith(aId)) {
		// String city_id=list.get(i).getCity_id();
		// String region_id=list.get(i).getRegion_id();
		// String region_name=list.get(i).getRegion_name();
		//
		// JSONObject tmpObj = new JSONObject();
		// tmpObj.put("city_id", city_id);
		// tmpObj.put("region_id", region_id);
		// tmpObj.put("region_name", region_name);
		// rl.add(tmpObj);
		// break;
		// }
		// }
		// }
		// if (rl.size() > 1) {
		// JSONObject tmpObj = new JSONObject();
		// tmpObj.put("city_id", "");
		// tmpObj.put("region_id", "");
		// tmpObj.put("region_name", "全部");
		// rl.add(0,tmpObj);
		// }
		resultMap.put("startTime", null == startTime ? "" : startTime);
		resultMap.put("endTime", null == endTime ? "" : endTime);
		resultMap.put("provList", null == provlistJson ? "" : provlistJson);
		resultMap.put("cityList", null == citylistJson ? "" : citylistJson);
		resultMap.put("fornList", null == fornlistJson ? "" : fornlistJson);
		resultMap.put("pieData", null == pieDataJson ? "" : pieDataJson);
		resultMap.put("provEdgeInfo", null == provEdgeJson ? "" : provEdgeJson);
		resultMap.put("cityEdgeInfo", null == cityEdgeJson ? "" : cityEdgeJson);
		resultMap.put("fornEdgeInfo", null == fornEdgeJson ? "" : fornEdgeJson);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 下载省来源分析数据 xiangzp
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	public void downloadProvRegionList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// Map<String, String> params = inputObject.getParams();// 获取查询条件信息
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime");
		if (endTime == null || endTime.equals("")) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_vst_src_d");
			inputObject.getParams().put("endTime", endTime);
		}
		String dateFormat = "";
		String startTime = inputObject.getParams().get("startTime");
		if (startTime == null || startTime.equals("")) { // 当日期为空时，设置默认日期
			if (endTime.length() == 8) {
				dateFormat = "yyyyMMdd";
				startTime = DateUtil.getInstance().getXDay(endTime, dateFormat,
						-6); // 前2周
			} else {
				dateFormat = "yyyyMM";
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						dateFormat, -12); // 前12个月
			}

			inputObject.getParams().put("startTime", startTime);
		}
		// 查询
		List<AnalysisBean> provlist = this.getBaseDao().queryForList(
				NAMESPACE + "queryProvRegionList", inputObject.getParams(),
				AnalysisBean.class);

		List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
		for (AnalysisBean bean : provlist) {
			Map<String, Object> map = new LinkedHashMap<String, Object>();
			map.put("prov_name", bean.getProv_name());
			map.put("vst_person_cnts", bean.getVst_person_cnts());
			dataList.add(map);
		}
		String rowNum = "2";
		String title = "来访省份::来访人数";
		String fileName = createDownloadFileName("来源分析",
				inputObject.getParams());
		String sheetName = "来源分析";
		String expType = "1";
		ExportBean export = new ExportBean(rowNum, title, fileName, sheetName,
				expType, dataList);
		outputObject.setObject(export);
	}

	/**
	 * 下载省内来源分析数据 xiangzp
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	public void downloadCityRegionList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// Map<String, String> params = inputObject.getParams();// 获取查询条件信息
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime");
		if (endTime == null || endTime.equals("")) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_vst_src_d");
			inputObject.getParams().put("endTime", endTime);
		}
		String dateFormat = "";
		String startTime = inputObject.getParams().get("startTime");
		if (startTime == null || startTime.equals("")) { // 当日期为空时，设置默认日期
			if (endTime.length() == 8) {
				dateFormat = "yyyyMMdd";
				startTime = DateUtil.getInstance().getXDay(endTime, dateFormat,
						-6); // 前2周
			} else {
				dateFormat = "yyyyMM";
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						dateFormat, -12); // 前12个月
			}

			inputObject.getParams().put("startTime", startTime);
		}
		// 查询
		List<AnalysisBean> citylist = this.getBaseDao().queryForList(
				NAMESPACE + "queryCityRegionList", inputObject.getParams(),
				AnalysisBean.class);

		List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
		for (AnalysisBean bean : citylist) {
			Map<String, Object> map = new LinkedHashMap<String, Object>();
			map.put("city_name", bean.getCity_name());
			map.put("vst_person_cnts", bean.getVst_person_cnts());
			dataList.add(map);
		}
		String rowNum = "2";
		String title = "来访地市::来访人数";
		String fileName = createDownloadFileName("来源分析",
				inputObject.getParams());
		String sheetName = "来源分析";
		String expType = "1";
		ExportBean export = new ExportBean(rowNum, title, fileName, sheetName,
				expType, dataList);
		outputObject.setObject(export);
	}

	/**
	 * 下载境外来源分析数据 mapf
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	public void downloadFornRegionList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// Map<String, String> params = inputObject.getParams();// 获取查询条件信息
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime");
		if (endTime == null || endTime.equals("")) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_vst_src_d");
			inputObject.getParams().put("endTime", endTime);
		}
		String dateFormat = "";
		String startTime = inputObject.getParams().get("startTime");
		if (startTime == null || startTime.equals("")) { // 当日期为空时，设置默认日期
			if (endTime.length() == 8) {
				dateFormat = "yyyyMMdd";
				startTime = DateUtil.getInstance().getXDay(endTime, dateFormat,
						-6); // 前2周
			} else {
				dateFormat = "yyyyMM";
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						dateFormat, -12); // 前12个月
			}

			inputObject.getParams().put("startTime", startTime);
		}
		// 查询
		List<CommonBaseBean> fornlist = this.getBaseDao().queryForList(
				NAMESPACE + "queryFornRegionList", inputObject.getParams(),
				CommonBaseBean.class);
		//处理commonbasebean里取得的境外游客数据
		List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
		for (CommonBaseBean bean : fornlist) {
			Map<String, Object> map = new LinkedHashMap<String, Object>();
			map.put("prov_name", bean.getQuery_value1());
			map.put("vst_person_cnts", bean.getQuery_value2());
			dataList.add(map);
		}
		String rowNum = "2";
		String title = "来访国家::来访人数";
		String fileName = createDownloadFileName("来源分析",
				inputObject.getParams());
		String sheetName = "来源分析";
		String expType = "1";
		ExportBean export = new ExportBean(rowNum, title, fileName, sheetName,
				expType, dataList);
		outputObject.setObject(export);
	}
	
	@Override
	public void queryStayLevelData(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime").replace("-", "")
				.replace("-", "");
		if (StringUtils.isBlank(endTime)) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_stay_cnts_d");
		}
		inputObject.getParams().put("endTime", endTime);

		String startTime = inputObject.getParams().get("startTime")
				.replace("-", "").replace("-", "");
		if (StringUtils.isBlank(startTime)) {
			if (endTime.length() == 8) {
				startTime = DateUtil.getInstance().getXDay(endTime, "yyyyMMdd",
						-6);
			} else {
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						"yyyyMM", -11);
			}
		}
		inputObject.getParams().put("startTime", startTime);

		String userId = inputObject.getParams().get("userId");
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		try {
			// 获取用户地市权限
			Map<String, List<String>> scopeMap = commonService
					.queryUserScope(userId);
			List<String> cityList = scopeMap.get(AreaBean.TYPE_CITY);
			String citys = StringUtils.join(cityList.iterator(), ",");
			inputObject.getParams().put("citys", citys);
			rList = this.getBaseDao().queryForList(
					NAMESPACE + "queryStayLevelData", inputObject.getParams(),
					CommonBaseBean.class);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		Map<String, List<String>> result = new HashMap<String, List<String>>();
		List<String> dataTimeList = new ArrayList<String>(); // 设置数据日期list

		if (rList != null && rList.size() > 0) {

			int nIndex = 0;

			// 分类填充省/内外数据
			for (CommonBaseBean bean : rList) {
				String opTime = bean.getQuery_value1();
				String stayLevel = bean.getQuery_value2();
				String vstPersonCnts = bean.getQuery_value3();

				// 按层次汇集数据
				List<String> personCntList = result.get(opTime);
				if (personCntList == null) {
					dataTimeList.add(opTime);
					personCntList = new ArrayList<String>();
					for (int i = 0; i < 5; i++) { // 暂定5个层级
						personCntList.add("-");
					}
					result.put(opTime, personCntList);
				}

				nIndex = Integer.parseInt(stayLevel) - 1;
				personCntList.set(nIndex, vstPersonCnts);
			}

			// this.appendObject("isEmpty", 0); // 结果数据是否为空
			resultMap.put("isEmpty", 0);
		} else {
			// this.appendObject("isEmpty", 1);
			resultMap.put("isEmpty", 1);
		}

		// this.appendObject("startTime", params.get("startTime")); // 设置数据时间
		// this.appendObject("endTime", params.get("endTime"));
		// String startTime = inputObject.getParams().get("startTime");
		// String endTime = inputObject.getParams().get("endTime");
		resultMap.put("startTime", null == startTime ? "" : startTime);
		resultMap.put("endTime", null == endTime ? "" : endTime);

		JSONObject stayLevelDataJson = JSONObject.fromObject(result);
		JSONArray dataTimeListJson = JSONArray.fromObject(dataTimeList);
		// this.appendObject("stayLevelData", stayLevelDataJson);
		// this.appendObject("dataTimeList", dataTimeListJson);
		resultMap.put("stayLevelData",
				null == stayLevelDataJson ? "" : stayLevelDataJson);
		resultMap.put("dataTimeList",
				null == dataTimeListJson ? "" : dataTimeListJson);

		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	@Override
	public void queryStayCntsData(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime").replace("-", "")
				.replace("-", "");
		if (StringUtils.isBlank(endTime)) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_stay_cnts_d");

		}
		inputObject.getParams().put("endTime", endTime);
		String startTime = inputObject.getParams().get("startTime")
				.replace("-", "").replace("-", "");
		if (StringUtils.isBlank(startTime)) {
			if (endTime.length() == 8) {
				startTime = DateUtil.getInstance().getXDay(endTime, "yyyyMMdd",
						-6);
			} else {
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						"yyyyMM", -11);
			}

		}
		inputObject.getParams().put("startTime", startTime);

		String userId = inputObject.getParams().get("userId");
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		try {
			// 获取用户地市权限
			Map<String, List<String>> scopeMap = commonService
					.queryUserScope(userId);
			List<String> cityList = scopeMap.get(AreaBean.TYPE_CITY);
			String citys = StringUtils.join(cityList.iterator(), ",");
			inputObject.getParams().put("citys", citys);
			rList = this.getBaseDao().queryForList(
					NAMESPACE + "queryStayCntsData", inputObject.getParams(),
					CommonBaseBean.class);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		Map<String, List<String>> result = new HashMap<String, List<String>>();
		List<String> dataTimeList = new ArrayList<String>(); // 设置数据日期list
		if (rList != null && rList.size() > 0) {

			int nIndex = 0;

			for (CommonBaseBean bean : rList) {
				String opTime = bean.getQuery_value1();
				String stayCntLevel = bean.getQuery_value2();
				String vstPersonCnts = bean.getQuery_value3();

				// 按层次汇集数据--已做排序，要求数据必须有序且不为空
				List<String> personCntList = result.get(opTime);
				if (personCntList == null) {
					dataTimeList.add(opTime);
					personCntList = new ArrayList<String>();
					for (int i = 0; i < 4; i++) { // 暂定4个层级
						personCntList.add("-");
					}
					result.put(opTime, personCntList);
				}

				nIndex = Integer.parseInt(stayCntLevel) - 1;
				personCntList.set(nIndex, vstPersonCnts);

				/*
				 * if ("1".equals(stayCntLevel)) { stayCntLevel1[nIndex] = cnt;
				 * } else if ("2".equals(stayCntLevel)) { stayCntLevel2[nIndex]
				 * = cnt; } else if ("3".equals(stayCntLevel)) {
				 * stayCntLevel3[nIndex] = cnt; } else { stayCntLevel4[nIndex] =
				 * cnt; }
				 */
			}
			// this.appendObject("isEmpty", 0); // 结果数据是否为空
			resultMap.put("isEmpty", 0);
		} else {
			// this.appendObject("isEmpty", 1);
			resultMap.put("isEmpty", 1);
		}
		JSONObject stayCntsDataJson = JSONObject.fromObject(result);
		JSONArray dataTimeListJson = JSONArray.fromObject(dataTimeList);
		// this.appendObject("stayCntsData", stayCntsDataJson);
		// this.appendObject("dataTimeList", dataTimeListJson);
		resultMap.put("stayCntsData",
				null == stayCntsDataJson ? "" : stayCntsDataJson);
		resultMap.put("dataTimeList",
				null == dataTimeListJson ? "" : dataTimeListJson);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 查询无参景区类型列表信息
	 * 
	 * @return void
	 *
	 * @author :sunyuan
	 * @date : 2016-01-21 上午11:10:20
	 *
	 */
	public void querySmsRegionList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<AnalysisBean> list = this.getBaseDao().queryForList(
				NAMESPACE + "querySmsRegionTypeList", inputObject.getParams(),
				AnalysisBean.class);
		resultMap.put("regionTypeList",
				null == list ? "" : JsonUtil.Object2Json(list));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}

	/**
	 * 下载驻留频次数据 xiangzp
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	public void downloadStayCntsTable(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime").replace("-", "")
				.replace("-", "");
		if (StringUtils.isBlank(endTime)) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_stay_cnts_d");

		}
		inputObject.getParams().put("endTime", endTime);
		String startTime = inputObject.getParams().get("startTime")
				.replace("-", "").replace("-", "");
		if (StringUtils.isBlank(startTime)) {
			if (endTime.length() == 8) {
				startTime = DateUtil.getInstance().getXDay(endTime, "yyyyMMdd",
						-6);
			} else {
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						"yyyyMM", -11);
			}

		}
		inputObject.getParams().put("startTime", startTime);

		String userId = inputObject.getParams().get("userId");
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		try {
			// 获取用户地市权限
			Map<String, List<String>> scopeMap = commonService
					.queryUserScope(userId);
			List<String> cityList = scopeMap.get(AreaBean.TYPE_CITY);
			String citys = StringUtils.join(cityList.iterator(), ",");
			inputObject.getParams().put("citys", citys);
			rList = this.getBaseDao().queryForList(
					NAMESPACE + "queryStayCntsData", inputObject.getParams(),
					CommonBaseBean.class);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
		if (rList != null && rList.size() > 0) {
			int nIndex = 0;
			for (CommonBaseBean bean : rList) {
				Map<String, Object> map = new LinkedHashMap<String, Object>();
				map.put("op_time", bean.getQuery_value1());
				map.put("stay_cnts", bean.getQuery_value2());
				map.put("vst_person_cnts", bean.getQuery_value3());
				dataList.add(map);
			}
			resultMap.put("isEmpty", 0);
		} else {
			// this.appendObject("isEmpty", 1);
			resultMap.put("isEmpty", 1);
		}
		String rowNum = "3";
		String title = "日期::驻留频次等级::客流人数";
		String fileName = createDownloadFileName("轨迹分析",
				inputObject.getParams());
		String sheetName = "轨迹分析";
		String expType = "1";
		ExportBean export = new ExportBean(rowNum, title, fileName, sheetName,
				expType, dataList);
		outputObject.setObject(export);
	}

	/**
	 * 下载驻留时长数据 xiangzp
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	public void downloadStayLevelTable(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		// 设置默认查询，依据 dim_data_time 中时间
		String endTime = inputObject.getParams().get("endTime").replace("-", "")
				.replace("-", "");
		if (StringUtils.isBlank(endTime)) {
			Map<String, String> dataTime = commonService.queryDataTime();
			endTime = dataTime.get("st_tour_region_stay_cnts_d");
		}
		inputObject.getParams().put("endTime", endTime);

		String startTime = inputObject.getParams().get("startTime")
				.replace("-", "").replace("-", "");
		if (StringUtils.isBlank(startTime)) {
			if (endTime.length() == 8) {
				startTime = DateUtil.getInstance().getXDay(endTime, "yyyyMMdd",
						-6);
			} else {
				startTime = DateUtil.getInstance().getOtherMonth(endTime,
						"yyyyMM", -11);
			}
		}
		inputObject.getParams().put("startTime", startTime);

		String userId = inputObject.getParams().get("userId");
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		try {
			// 获取用户地市权限
			Map<String, List<String>> scopeMap = commonService
					.queryUserScope(userId);
			List<String> cityList = scopeMap.get(AreaBean.TYPE_CITY);
			String citys = StringUtils.join(cityList.iterator(), ",");
			inputObject.getParams().put("citys", citys);
			rList = this.getBaseDao().queryForList(
					NAMESPACE + "queryStayLevelData", inputObject.getParams(),
					CommonBaseBean.class);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
		if (rList != null && rList.size() > 0) {
			int nIndex = 0;
			// 分类填充省/内外数据
			for (CommonBaseBean bean : rList) {
				Map<String, Object> map = new LinkedHashMap<String, Object>();
				map.put("op_time", bean.getQuery_value1());
				map.put("stay_level", bean.getQuery_value2());
				map.put("vst_person_cnts", bean.getQuery_value3());
				dataList.add(map);
			}
			resultMap.put("isEmpty", 0);
		} else {
			resultMap.put("isEmpty", 1);
		}
		String rowNum = "3";
		String title = "日期::驻留时长等级::客流人数";
		String fileName = createDownloadFileName("轨迹分析",
				inputObject.getParams());
		String sheetName = "轨迹分析";
		String expType = "1";
		ExportBean export = new ExportBean(rowNum, title, fileName, sheetName,
				expType, dataList);
		outputObject.setObject(export);
	}

	/**
	 * @Description : 生成下载文件名称
	 * 
	 * @return String 文件名
	 *
	 * @author : xuxiong
	 * @date : 2015年12月24日 下午3:36:07
	 * 
	 */
	private String createDownloadFileName(String functionName,
			Map<String, String> params) {
		StringBuilder fileName = new StringBuilder();
		fileName.append(functionName);

		Map<String, AreaBean> cityMap = AreaCache.areaCache
				.get(AreaBean.TYPE_CITY);
		Map<String, AreaBean> regionMap = AreaCache.areaCache
				.get(AreaBean.TYPE_REGION);

		String cityId = params.get("cityId");
		if (StringUtils.isNotBlank(cityId)) {
			fileName.append("_").append(cityMap.get(cityId).getAreaName());
		} else {
			fileName.append("_全省");
		}

		String regionType = params.get("regionType");
		if (StringUtils.isNotBlank(regionType)) {
			fileName.append("_").append(regionType).append("A");
		} else {
			fileName.append("_全部类型");
		}

		String regionId = params.get("regionId");
		if (StringUtils.isNotBlank(regionId)) {
			fileName.append("_").append(regionMap.get(regionId).getAreaName());
		} else {
			fileName.append("_全部景区");
		}

		String startTime = params.get("startTime");
		if (StringUtils.isNotBlank(startTime)) {
			fileName.append("_").append(startTime);
		}

		String endTime = params.get("endTime");
		if (StringUtils.isNotBlank(endTime) && !startTime.equals(endTime)) {
			fileName.append("-").append(endTime);
		}

		return fileName.toString();
	}

	// @Override
	// public void queryAgeAnalysisDate(InputObject inputObject, OutputObject
	// outputObject) throws BusinessException {
	// String cityId = inputObject.getParams().get("cityId");
	// String lineId = inputObject.getParams().get("lineId");
	// String monthStart =
	// inputObject.getParams().get("monthStart").replace("-", "");
	// String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
	// "");
	// Map map = new HashMap();
	// map.put("cityId", cityId);
	// map.put("monthStart", monthStart);
	// map.put("monthEnd", monthEnd);
	// map.put("lineId", lineId);
	// List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
	// try {
	// rList = this.getBaseDao().queryForList(NAMESPACE +
	// "queryAgeAnalysisDate", map, CommonBaseBean.class);
	//
	// } catch (Exception e) {
	// System.out.println(e.getMessage());
	// }
	// // JSONArray data = JSONArray.fromObject(rList);
	// // Map<String, Object> resultMap = new HashMap<String, Object>();
	// // resultMap.put("result", null == rList ? "" :
	// // JsonUtil.Object2Json(rList));
	// // outputObject.setObject(JsonUtil.Object2Json(resultMap));
	// List<JSONObject> rl = new ArrayList<JSONObject>();
	// for (int i = 0; i < rList.size(); i++) {
	// String ageCatagory = rList.get(i).getQuery_value1();
	// String cnts = rList.get(i).getQuery_value2();
	// JSONObject tmpObj = new JSONObject();
	// tmpObj.put("ageCatagory", ageCatagory);
	// tmpObj.put("cnts", cnts);
	// rl.add(tmpObj);
	// }
	//
	// Map<String, Object> resultMap = new HashMap<String, Object>();
	// resultMap.put("result", null == rl ? "" : JsonUtil.Object2Json(rl));
	// outputObject.setObject(JsonUtil.Object2Json(resultMap));
	// }

	// 查询旅游线路列表
	// @Override
	// public void queryRouteList(InputObject inputObject, OutputObject
	// outputObject) throws BusinessException {
	// String cityId = inputObject.getParams().get("cityId");
	// String monthStart =
	// inputObject.getParams().get("monthStart").replace("-", "");
	// String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
	// "");
	// int count = 0;
	// Map map = new HashMap();
	// map.put("cityId", cityId);
	// map.put("monthStart", monthStart);
	// map.put("monthEnd", monthEnd);
	// List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
	// try {
	// rList = this.getBaseDao().queryForList(NAMESPACE + "queryRouteList", map,
	// CommonBaseBean.class);
	// } catch (Exception e) {
	// System.out.println(e.getMessage());
	// }
	// List<JSONObject> rl = new ArrayList<JSONObject>();
	// for (int i = 0; i < rList.size() && i < 4; i++) {
	// String lineId = rList.get(i).getQuery_value1();
	// String lineName = rList.get(i).getQuery_value2();
	// double cnts = Double.parseDouble(rList.get(i).getQuery_value3());
	// JSONObject tmpObj = new JSONObject();
	// tmpObj.put("lineId", lineId);
	// tmpObj.put("lineName", lineName);
	// // double db=Integer.parseInt(cnts)/10000;
	// // double cnt=new
	// // BigDecimal(db).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
	// // //四舍五入，保留1位小数
	// tmpObj.put("cnts", cnts);
	// rl.add(tmpObj);
	// count += cnts; // 获取总人数
	// }
	// Map map2 = new HashMap();
	// map2.put("rl", rl);
	// map2.put("count", count);
	// JSONObject data = JSONObject.fromObject(map2);
	// Map<String, Object> resultMap = new HashMap<String, Object>();
	// resultMap.put("result", null == data ? "" : JsonUtil.Object2Json(data));
	// outputObject.setObject(JsonUtil.Object2Json(resultMap));
	// }

	// 性别分析
	// @Override
	// public void queryGenderData(InputObject inputObject, OutputObject
	// outputObject) throws BusinessException {
	// String cityId = inputObject.getParams().get("cityId");
	// String lineId = inputObject.getParams().get("lineId");
	// String monthStart =
	// inputObject.getParams().get("monthStart").replace("-", "");
	// String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
	// "");
	// Map map = new HashMap();
	// map.put("cityId", cityId);
	// map.put("monthStart", monthStart);
	// map.put("monthEnd", monthEnd);
	// map.put("lineId", lineId);
	// List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
	// try {
	// rList = this.getBaseDao().queryForList(NAMESPACE + "queryGenderData",
	// map, CommonBaseBean.class);
	//
	// } catch (Exception e) {
	// System.out.println(e.getMessage());
	// }
	// List<JSONObject> rl = new ArrayList<JSONObject>();
	// for (int i = 0; i < rList.size(); i++) {
	// String sex = rList.get(i).getQuery_value1();
	// String cnts = rList.get(i).getQuery_value2();
	// JSONObject tmpObj = new JSONObject();
	// tmpObj.put("sex", sex);
	// tmpObj.put("cnts", cnts);
	// rl.add(tmpObj);
	// }
	// Map<String, Object> resultMap = new HashMap<String, Object>();
	// resultMap.put("result", null == rl ? "" : JsonUtil.Object2Json(rl));
	// outputObject.setObject(JsonUtil.Object2Json(resultMap));
	// }

	// 路线驻留分类分析
	@Override
	public void queryStayStyleData(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		String cityId = inputObject.getParams().get("cityId");
		String lineId = inputObject.getParams().get("lineId");
		String monthStart = inputObject.getParams().get("monthStart")
				.replace("-", "");
		String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
				"");
		Map map = new HashMap();
		map.put("cityId", cityId);
		map.put("monthStart", monthStart);
		map.put("monthEnd", monthEnd);
		map.put("lineId", lineId);
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		try {
			rList = this.getBaseDao().queryForList(
					NAMESPACE + "queryAgeAnalysisDate", map,
					CommonBaseBean.class);

		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		// JSONArray data = JSONArray.fromObject(rList);
		// Map<String, Object> resultMap = new HashMap<String, Object>();
		// resultMap.put("result", null == rList ? "" :
		// JsonUtil.Object2Json(rList));
		// outputObject.setObject(JsonUtil.Object2Json(resultMap));
		List<JSONObject> rl = new ArrayList<JSONObject>();
		for (int i = 0; i < rList.size(); i++) {
			String ageCatagory = rList.get(i).getQuery_value1();
			String cnts = rList.get(i).getQuery_value2();
			JSONObject tmpObj = new JSONObject();
			tmpObj.put("ageCatagory", ageCatagory);
			tmpObj.put("cnts", cnts);
			rl.add(tmpObj);
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("result", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	// 消费能力列表
	// @Override
	// public void queryConsumeAbilityData(InputObject inputObject, OutputObject
	// outputObject) throws BusinessException {
	// String cityId = inputObject.getParams().get("cityId");
	// String lineId = inputObject.getParams().get("lineId");
	// String monthStart =
	// inputObject.getParams().get("monthStart").replace("-", "");
	// String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
	// "");
	// Map map = new HashMap();
	// map.put("cityId", cityId);
	// map.put("monthStart", monthStart);
	// map.put("monthEnd", monthEnd);
	// map.put("lineId", lineId);
	// List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
	// try {
	// rList = this.getBaseDao().queryForList(NAMESPACE +
	// "queryConsumeAbilityData", map, CommonBaseBean.class);
	//
	// } catch (Exception e) {
	// System.out.println(e.getMessage());
	// }
	// List axisNames = new ArrayList();
	// List axisValues = new ArrayList();
	// int cnts = 0;
	// for (int i = 0; i < rList.size(); i++) {
	// String axisName = rList.get(i).getQuery_value1();
	// int axisValue = Integer.parseInt(rList.get(i).getQuery_value2());
	// axisNames.add(axisName);
	// axisValues.add(axisValue);
	// cnts += axisValue;
	// }
	// Map map2 = new HashMap();
	// map2.put("axisNames", axisNames);
	// map2.put("axisValues", axisValues);
	// map2.put("cnts", cnts);
	// JSONObject data = JSONObject.fromObject(map2);
	// Map<String, Object> resultMap = new HashMap<String, Object>();
	// resultMap.put("result", null == data ? "" : JsonUtil.Object2Json(data));
	// outputObject.setObject(JsonUtil.Object2Json(resultMap));
	// }

	// 查询户籍地和手机品牌数据
	// @Override
	// public void provCodeTermBrandData(InputObject inputObject, OutputObject
	// outputObject) throws BusinessException {
	// String cityId = inputObject.getParams().get("cityId");
	// String lineId = inputObject.getParams().get("lineId");
	// String monthStart =
	// inputObject.getParams().get("monthStart").replace("-", "");
	// String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
	// "");
	// Map map = new HashMap();
	// map.put("cityId", cityId);
	// map.put("monthStart", monthStart);
	// map.put("monthEnd", monthEnd);
	// map.put("lineId", lineId);
	// List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
	// try {
	// rList = this.getBaseDao().queryForList(NAMESPACE + "queryProvCodeData",
	// map, CommonBaseBean.class);
	//
	// } catch (Exception e) {
	// System.out.println(e.getMessage());
	// }
	// List axisProvs = new ArrayList();
	// List axisValues = new ArrayList();
	// int cnts = 0;
	// for (int i = 0; i < rList.size(); i++) {
	// int axisValue = Integer.parseInt(rList.get(i).getQuery_value2());
	// cnts += axisValue;
	// }
	// for (int i = 0; i < rList.size() && i < 5; i++) {
	// String axisProv = rList.get(i).getQuery_value1();
	// int axisValue = Integer.parseInt(rList.get(i).getQuery_value2());
	// axisProvs.add(axisProv);
	// axisValues.add(axisValue);
	// }
	// for (int i = 0; i < axisValues.size(); i++) {
	// // double val=((double)axisValues.get(i))/cnts*100;
	// // String percent=new java.text.DecimalFormat("0.0").format(val);
	// double db = (double) ((int) axisValues.get(i)) / cnts * 100;
	// double percent = new BigDecimal(db).setScale(1,
	// BigDecimal.ROUND_HALF_UP).doubleValue(); // 四舍五入，保留1位小数
	// axisValues.set(i, percent);
	//
	// }
	// JSONArray axisProvsJson = JSONArray.fromObject(axisProvs);
	// JSONArray axisValuesJson = JSONArray.fromObject(axisValues);
	//
	// // 手机品牌分析
	// List<CommonBaseBean> rList2 = new ArrayList<CommonBaseBean>();
	// try {
	// rList2 = this.getBaseDao().queryForList(NAMESPACE + "queryTermBrandData",
	// map, CommonBaseBean.class);
	//
	// } catch (Exception e) {
	// System.out.println(e.getMessage());
	// }
	// List<JSONObject> rList3Json = new ArrayList<JSONObject>();
	// List rList4 = new ArrayList();
	// for (int i = 0; i < rList2.size(); i++) {
	// String brands = rList2.get(i).getQuery_value1();
	// String counts = rList2.get(i).getQuery_value2();
	// JSONObject tmpObj = new JSONObject();
	// tmpObj.put("name", brands);
	// tmpObj.put("value", counts);
	// rList3Json.add(tmpObj);
	// rList4.add(brands);
	// }
	// JSONArray rList4Json = JSONArray.fromObject(rList4);
	// // Map map2=new HashMap();
	// // map2.put("axisProvs",axisProvs);
	// // map2.put("axisValues", axisValues);
	// // JSONObject data = JSONObject.fromObject(map2);
	// Map<String, Object> resultMap = new HashMap<String, Object>();
	// resultMap.put("axisProvsJson", null == axisProvsJson ? "" :
	// JsonUtil.Object2Json(axisProvsJson));
	// resultMap.put("axisValuesJson", null == axisValuesJson ? "" :
	// JsonUtil.Object2Json(axisValuesJson));
	// resultMap.put("termBrand", null == rList3Json ? "" :
	// JsonUtil.Object2Json(rList3Json));
	// resultMap.put("legend", null == rList4Json ? "" :
	// JsonUtil.Object2Json(rList4Json));
	// outputObject.setObject(JsonUtil.Object2Json(resultMap));
	// }

	// 查询游客住宿数据
	// @Override
	// public void queryAccommodationPie(InputObject inputObject, OutputObject
	// outputObject) throws BusinessException {
	// String cityId = inputObject.getParams().get("cityId");
	// String monthStart =
	// inputObject.getParams().get("monthStart").replace("-", "");
	// String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
	// "");
	// Map map = new HashMap();
	// map.put("cityId", cityId);
	// map.put("monthStart", monthStart);
	// map.put("monthEnd", monthEnd);
	// List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
	// try {
	// rList = this.getBaseDao().queryForList(NAMESPACE + "queryAccomData", map,
	// CommonBaseBean.class);
	//
	// } catch (Exception e) {
	// System.out.println(e.getMessage());
	// }
	// List rList3 = new ArrayList();
	// List rList2 = new ArrayList();
	// for (int i = 0; i < rList.size(); i++) {
	// String category = rList.get(i).getQuery_value1();
	// String counts = rList.get(i).getQuery_value2();
	// JSONObject tmpObj = new JSONObject();
	// category = category.equals("0") ? "省内过夜用户" : (category.equals("1") ?
	// "省外过夜用户" : "境外过夜用户");
	// tmpObj.put("name", category);
	// tmpObj.put("value", counts);
	// rList2.add(tmpObj);
	// rList3.add(category);
	// }
	// JSONArray rList2Json = JSONArray.fromObject(rList2);
	// JSONArray rList3Json = JSONArray.fromObject(rList3);
	// Map<String, Object> resultMap = new HashMap<String, Object>();
	// resultMap.put("data", null == rList2Json ? "" :
	// JsonUtil.Object2Json(rList2Json));
	// resultMap.put("legend", null == rList3Json ? "" :
	// JsonUtil.Object2Json(rList3Json));
	// outputObject.setObject(JsonUtil.Object2Json(resultMap));
	//
	// }

	// 初始化主题数据
	@Override
	public void queryThemeList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		String cityId = inputObject.getParams().get("cityId");
		String monthStart = inputObject.getParams().get("monthStart")
				.replace("-", "");
		String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
				"");
		int count = 0;
		Map map = new HashMap();
		map.put("cityId", cityId);
		map.put("monthStart", monthStart);
		map.put("monthEnd", monthEnd);
		// route
		List<CommonBaseBean> listRoute = new ArrayList<CommonBaseBean>();
		try {
			listRoute = this.getBaseDao().queryForList(
					NAMESPACE + "queryRouteList", map, CommonBaseBean.class);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		List<JSONObject> rRoute = new ArrayList<JSONObject>();
		for (int i = 0; i < listRoute.size() && i < 10; i++) {
			String lineId = listRoute.get(i).getQuery_value1();
			String lineName = listRoute.get(i).getQuery_value2();
			double cnts = Double
					.parseDouble(listRoute.get(i).getQuery_value3());
			JSONObject tmpObj = new JSONObject();
			tmpObj.put("lineId", lineId);
			tmpObj.put("lineName", lineName);
			// double db=Integer.parseInt(cnts)/10000;
			// double cnt=new
			// BigDecimal(db).setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();
			// //四舍五入，保留1位小数
			tmpObj.put("cnts", cnts);
			rRoute.add(tmpObj);
			count += cnts; // 获取总人数
		}
		Map mapRoute = new HashMap();
		mapRoute.put("rRoute", rRoute);
		mapRoute.put("count", count);
		JSONObject routeJson = JSONObject.fromObject(mapRoute);
		// Accommodation
		List<CommonBaseBean> listAccom = new ArrayList<CommonBaseBean>();
		try {
			listAccom = this.getBaseDao().queryForList(
					NAMESPACE + "queryAccomData", map, CommonBaseBean.class);

		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		List rList3 = new ArrayList();
		List rList2 = new ArrayList();
		for (int i = 0; i < listAccom.size(); i++) {
			String category = listAccom.get(i).getQuery_value1();
			String counts = listAccom.get(i).getQuery_value2();
			JSONObject tmpObj = new JSONObject();
			category = category.equals("0") ? "省内过夜用户"
					: (category.equals("1") ? "省外过夜用户" : "境外过夜用户");
			tmpObj.put("name", category);
			tmpObj.put("value", counts);
			rList2.add(tmpObj);
			rList3.add(category);
		}
		JSONArray rList2Json = JSONArray.fromObject(rList2);
		JSONArray rList3Json = JSONArray.fromObject(rList3);

		// TourismDays
		List<CommonBaseBean> tourismDaysList = new ArrayList<CommonBaseBean>();
		try {
			tourismDaysList = this.getBaseDao().queryForList(
					NAMESPACE + "querytourismDays", map, CommonBaseBean.class);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		List axisNames = new ArrayList();
		List axisValues = new ArrayList();
		// int cnts = 0;
		for (int i = 0; i < tourismDaysList.size(); i++) {
			String axisName = tourismDaysList.get(i).getQuery_value1();
			if (axisName.equals("1")) {
				axisName = "一日游";
			}
			if (axisName.equals("2")) {
				axisName = "二日游";
			}
			if (axisName.equals("3")) {
				axisName = "三日游";
			}
			if (axisName.equals("4")) {
				axisName = "四日游";
			}
			int axisValue = Integer
					.parseInt(tourismDaysList.get(i).getQuery_value2());
			axisNames.add(axisName);
			axisValues.add(axisValue);
			// cnts += axisValue;
		}
		Map TourismDaysMap = new HashMap();
		TourismDaysMap.put("axisNames", axisNames);
		TourismDaysMap.put("axisValues", axisValues);
		// TourismDaysMap.put("cnts", cnts);
		JSONObject TourismDaysJson = JSONObject.fromObject(TourismDaysMap);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("data",
				null == rList2Json ? "" : JsonUtil.Object2Json(rList2Json));
		resultMap.put("legend",
				null == rList3Json ? "" : JsonUtil.Object2Json(rList3Json));
		resultMap.put("routeList",
				null == routeJson ? "" : JsonUtil.Object2Json(routeJson));
		resultMap.put("TourismDays",
				null == routeJson ? "" : JsonUtil.Object2Json(TourismDaysJson));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	// 维度数据查询
	@Override
	public void queryDimentionData(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		String cityId = inputObject.getParams().get("cityId");
		String staticParam = inputObject.getParams().get("staticParam");
		String monthStart = inputObject.getParams().get("monthStart")
				.replace("-", "");
		String monthEnd = inputObject.getParams().get("monthEnd").replace("-",
				"");
		Map map = new HashMap();
		map.put("cityId", cityId);
		map.put("monthStart", monthStart);
		map.put("monthEnd", monthEnd);
		if (staticParam.split(":")[0].equals("route")) {
			map.put("lineId", staticParam.split(":")[1]);
			// 1.年龄类别
			List<CommonBaseBean> listAge = new ArrayList<CommonBaseBean>();
			try {
				listAge = this.getBaseDao().queryForList(
						NAMESPACE + "queryAgeAnalysisData", map,
						CommonBaseBean.class);
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> ageJson = new ArrayList<JSONObject>();
			for (int i = 0; i < listAge.size(); i++) {
				String ageCatagory = listAge.get(i).getQuery_value1();
				String cnts = listAge.get(i).getQuery_value2();
				JSONObject ageTmpObj = new JSONObject();
				ageTmpObj.put("ageCatagory", ageCatagory);
				ageTmpObj.put("cnts", cnts);
				ageJson.add(ageTmpObj);
			}
			// 2.性别分类
			List<CommonBaseBean> genderList = new ArrayList<CommonBaseBean>();
			try {
				genderList = this.getBaseDao().queryForList(
						NAMESPACE + "queryGenderData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> genderJson = new ArrayList<JSONObject>();
			for (int i = 0; i < genderList.size(); i++) {
				String sex = genderList.get(i).getQuery_value1();
				String cnts = genderList.get(i).getQuery_value2();
				JSONObject genderTmpObj = new JSONObject();
				genderTmpObj.put("sex", sex);
				genderTmpObj.put("cnts", cnts);
				genderJson.add(genderTmpObj);
			}
			// 3.消费能力分析
			List<CommonBaseBean> listConsumeAbility = new ArrayList<CommonBaseBean>();
			try {
				listConsumeAbility = this.getBaseDao().queryForList(
						NAMESPACE + "queryConsumeAbilityData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List axisNames = new ArrayList();
			List axisValues = new ArrayList();
			int cnts = 0;
			for (int i = 0; i < listConsumeAbility.size(); i++) {
				String axisName = listConsumeAbility.get(i).getQuery_value1();
				int axisValue = Integer
						.parseInt(listConsumeAbility.get(i).getQuery_value2());
				axisNames.add(axisName);
				axisValues.add(axisValue);
				cnts += axisValue;
			}
			Map consumeAbilitymap = new HashMap();
			consumeAbilitymap.put("axisNames", axisNames);
			consumeAbilitymap.put("axisValues", axisValues);
			consumeAbilitymap.put("cnts", cnts);
			JSONObject consumeAbilityJson = JSONObject
					.fromObject(consumeAbilitymap);

			// 4.游客来源分析
			List<CommonBaseBean> listProvCode = new ArrayList<CommonBaseBean>();
			try {
				listProvCode = this.getBaseDao().queryForList(
						NAMESPACE + "queryProvCodeData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List axisProvs = new ArrayList();
			List axisProvValues = new ArrayList();
			int ProvCnts = 0;
			for (int i = 0; i < listProvCode.size(); i++) {
				int axisCntValue = Integer
						.parseInt(listProvCode.get(i).getQuery_value2());
				ProvCnts += axisCntValue;
			}
			for (int i = 0; i < listProvCode.size() && i < 5; i++) {
				String axisProv = listProvCode.get(i).getQuery_value1();
				int axisCntValue = Integer
						.parseInt(listProvCode.get(i).getQuery_value2());
				axisProvs.add(axisProv);
				axisProvValues.add(axisCntValue);
			}
			for (int i = 0; i < axisProvValues.size(); i++) {
				// double val=((double)axisValues.get(i))/cnts*100;
				// String percent=new
				// java.text.DecimalFormat("0.0").format(val);
				double db = (double) ((int) axisProvValues.get(i)) / cnts * 100;
				double percent = new BigDecimal(db)
						.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); // 四舍五入，保留1位小数
				axisProvValues.set(i, percent);

			}
			JSONArray axisProvsJson = JSONArray.fromObject(axisProvs);
			JSONArray axisProvValuesJson = JSONArray.fromObject(axisProvValues);

			// 5.手机品牌分析
			List<CommonBaseBean> listBrand = new ArrayList<CommonBaseBean>();
			try {
				listBrand = this.getBaseDao().queryForList(
						NAMESPACE + "queryTermBrandData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> listBrandJson = new ArrayList<JSONObject>();
			List brandList = new ArrayList();
			int otherCnts = 0;
			int num = 0;
			for (int i = 0; i < listBrand.size(); i++) {
				String brands = listBrand.get(i).getQuery_value1();
				String counts = listBrand.get(i).getQuery_value2();
				JSONObject tmpObj = new JSONObject();
				if (num < 8) {
					num++;
					tmpObj.put("name", brands);
					tmpObj.put("value", counts);
					listBrandJson.add(tmpObj);
					brandList.add(brands);
				} else {
					otherCnts += Integer.parseInt(counts);
				}
			}
			if (otherCnts != 0) {
				JSONObject othTmpObj = new JSONObject();
				othTmpObj.put("name", "其他");
				othTmpObj.put("value", String.valueOf(otherCnts));
				listBrandJson.add(othTmpObj);
				brandList.add("其他");
			}
			JSONArray brandListJson = JSONArray.fromObject(brandList);

			Map<String, Object> resultMap = new HashMap<String, Object>();
			resultMap.put("ageListData",
					null == ageJson ? "" : JsonUtil.Object2Json(ageJson));
			resultMap.put("genderListData",
					null == genderJson ? "" : JsonUtil.Object2Json(genderJson));
			resultMap.put("consumeAbilityData", null == consumeAbilityJson ? ""
					: JsonUtil.Object2Json(consumeAbilityJson));
			resultMap.put("axisProvsJson", null == axisProvsJson ? ""
					: JsonUtil.Object2Json(axisProvsJson));
			resultMap.put("axisProvValuesJson", null == axisProvValuesJson ? ""
					: JsonUtil.Object2Json(axisProvValuesJson));
			resultMap.put("termBrand", null == listBrandJson ? ""
					: JsonUtil.Object2Json(listBrandJson));
			resultMap.put("legend", null == brandListJson ? ""
					: JsonUtil.Object2Json(brandListJson));
			outputObject.setObject(JsonUtil.Object2Json(resultMap));
		}
		if (staticParam.split(":")[0].equals("accommodation")) {
			String sourceName = staticParam.split(":")[1];
			String sourceId = sourceName.equals("省内过夜用户") ? "0"
					: (sourceName.equals("省外过夜用户") ? "1" : "2");
			map.put("sourceId", sourceId);
			// 1.年龄类别
			List<CommonBaseBean> listAge = new ArrayList<CommonBaseBean>();
			try {
				listAge = this.getBaseDao().queryForList(
						NAMESPACE + "queryAccomAgeData", map,
						CommonBaseBean.class);
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> ageJson = new ArrayList<JSONObject>();
			for (int i = 0; i < listAge.size(); i++) {
				String ageCatagory = listAge.get(i).getQuery_value1();
				String cnts = listAge.get(i).getQuery_value2();
				JSONObject ageTmpObj = new JSONObject();
				ageTmpObj.put("ageCatagory", ageCatagory);
				ageTmpObj.put("cnts", cnts);
				ageJson.add(ageTmpObj);
			}
			// 2.性别分类
			List<CommonBaseBean> genderList = new ArrayList<CommonBaseBean>();
			try {
				genderList = this.getBaseDao().queryForList(
						NAMESPACE + "queryAccomGenderData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> genderJson = new ArrayList<JSONObject>();
			for (int i = 0; i < genderList.size(); i++) {
				String sex = genderList.get(i).getQuery_value1();
				String cnts = genderList.get(i).getQuery_value2();
				JSONObject genderTmpObj = new JSONObject();
				genderTmpObj.put("sex", sex);
				genderTmpObj.put("cnts", cnts);
				genderJson.add(genderTmpObj);
			}
			// 3.消费能力分析
			List<CommonBaseBean> listConsumeAbility = new ArrayList<CommonBaseBean>();
			try {
				listConsumeAbility = this.getBaseDao().queryForList(
						NAMESPACE + "queryAccomConsumeAbilityData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List axisNames = new ArrayList();
			List axisValues = new ArrayList();
			int cnts = 0;
			for (int i = 0; i < listConsumeAbility.size(); i++) {
				String axisName = listConsumeAbility.get(i).getQuery_value1();
				int axisValue = Integer
						.parseInt(listConsumeAbility.get(i).getQuery_value2());
				axisNames.add(axisName);
				axisValues.add(axisValue);
				cnts += axisValue;
			}
			Map consumeAbilitymap = new HashMap();
			consumeAbilitymap.put("axisNames", axisNames);
			consumeAbilitymap.put("axisValues", axisValues);
			consumeAbilitymap.put("cnts", cnts);
			JSONObject consumeAbilityJson = JSONObject
					.fromObject(consumeAbilitymap);

			// 4.游客来源分析
			List<CommonBaseBean> listProvCode = new ArrayList<CommonBaseBean>();
			try {
				listProvCode = this.getBaseDao().queryForList(
						NAMESPACE + "queryAccomProvCodeData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List axisProvs = new ArrayList();
			List axisProvValues = new ArrayList();
			int ProvCnts = 0;
			for (int i = 0; i < listProvCode.size(); i++) {
				int axisCntValue = Integer
						.parseInt(listProvCode.get(i).getQuery_value2());
				ProvCnts += axisCntValue;
			}
			for (int i = 0; i < listProvCode.size() && i < 5; i++) {
				String axisProv = listProvCode.get(i).getQuery_value1();
				int axisCntValue = Integer
						.parseInt(listProvCode.get(i).getQuery_value2());
				axisProvs.add(axisProv);
				axisProvValues.add(axisCntValue);
			}
			for (int i = 0; i < axisProvValues.size(); i++) {
				// double val=((double)axisValues.get(i))/cnts*100;
				// String percent=new
				// java.text.DecimalFormat("0.0").format(val);
				double db = (double) ((int) axisProvValues.get(i)) / cnts * 100;
				double percent = new BigDecimal(db)
						.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); // 四舍五入，保留1位小数
				axisProvValues.set(i, percent);

			}
			JSONArray axisProvsJson = JSONArray.fromObject(axisProvs);
			JSONArray axisProvValuesJson = JSONArray.fromObject(axisProvValues);

			// 5.手机品牌分析
			List<CommonBaseBean> listBrand = new ArrayList<CommonBaseBean>();
			try {
				listBrand = this.getBaseDao().queryForList(
						NAMESPACE + "queryAccomTermBrandData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> listBrandJson = new ArrayList<JSONObject>();
			List brandList = new ArrayList();
			int otherCnts = 0, num = 0;
			for (int i = 0; i < listBrand.size(); i++) {
				String brands = listBrand.get(i).getQuery_value1();
				String counts = listBrand.get(i).getQuery_value2();
				JSONObject tmpObj = new JSONObject();
				if (num < 8) {
					num++;
					tmpObj.put("name", brands);
					tmpObj.put("value", counts);
					listBrandJson.add(tmpObj);
					brandList.add(brands);
				} else {
					otherCnts += Integer.parseInt(counts);
				}
			}
			if (otherCnts != 0) {
				JSONObject othTmpObj = new JSONObject();
				othTmpObj.put("name", "其他");
				othTmpObj.put("value", String.valueOf(otherCnts));
				listBrandJson.add(othTmpObj);
				brandList.add("其他");
			}
			JSONArray brandListJson = JSONArray.fromObject(brandList);

			Map<String, Object> resultMap = new HashMap<String, Object>();
			resultMap.put("ageListData",
					null == ageJson ? "" : JsonUtil.Object2Json(ageJson));
			resultMap.put("genderListData",
					null == genderJson ? "" : JsonUtil.Object2Json(genderJson));
			resultMap.put("consumeAbilityData", null == consumeAbilityJson ? ""
					: JsonUtil.Object2Json(consumeAbilityJson));
			resultMap.put("axisProvsJson", null == axisProvsJson ? ""
					: JsonUtil.Object2Json(axisProvsJson));
			resultMap.put("axisProvValuesJson", null == axisProvValuesJson ? ""
					: JsonUtil.Object2Json(axisProvValuesJson));
			resultMap.put("termBrand", null == listBrandJson ? ""
					: JsonUtil.Object2Json(listBrandJson));
			resultMap.put("legend", null == brandListJson ? ""
					: JsonUtil.Object2Json(brandListJson));
			outputObject.setObject(JsonUtil.Object2Json(resultMap));
		} // if
		if (staticParam.split(":")[0].equals("tourismDays")) {
			String TOURIST_DAYS = staticParam.split(":")[1];
			int day = Integer.parseInt(TOURIST_DAYS) + 1;
			map.put("days", String.valueOf(day));
			// 1.年龄类别
			List<CommonBaseBean> listAge = new ArrayList<CommonBaseBean>();
			try {
				listAge = this.getBaseDao().queryForList(
						NAMESPACE + "queryTourismAgeData", map,
						CommonBaseBean.class);
			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> ageJson = new ArrayList<JSONObject>();
			for (int i = 0; i < listAge.size(); i++) {
				String ageCatagory = listAge.get(i).getQuery_value1();
				String cnts = listAge.get(i).getQuery_value2();
				JSONObject ageTmpObj = new JSONObject();
				ageTmpObj.put("ageCatagory", ageCatagory);
				ageTmpObj.put("cnts", cnts);
				ageJson.add(ageTmpObj);
			}
			// 2.性别分类
			List<CommonBaseBean> genderList = new ArrayList<CommonBaseBean>();
			try {
				genderList = this.getBaseDao().queryForList(
						NAMESPACE + "queryToursmGenderData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> genderJson = new ArrayList<JSONObject>();
			for (int i = 0; i < genderList.size(); i++) {
				String sex = genderList.get(i).getQuery_value1();
				String cnts = genderList.get(i).getQuery_value2();
				JSONObject genderTmpObj = new JSONObject();
				genderTmpObj.put("sex", sex);
				genderTmpObj.put("cnts", cnts);
				genderJson.add(genderTmpObj);
			}
			// 3.消费能力分析
			List<CommonBaseBean> listConsumeAbility = new ArrayList<CommonBaseBean>();
			try {
				listConsumeAbility = this.getBaseDao().queryForList(
						NAMESPACE + "queryTourismConsumeAbilityData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List axisNames = new ArrayList();
			List axisValues = new ArrayList();
			int cnts = 0;
			for (int i = 0; i < listConsumeAbility.size(); i++) {
				String axisName = listConsumeAbility.get(i).getQuery_value1();
				if (axisName.equals("") || axisName.equals(null)) {
				} else {
					int axisValue = Integer.parseInt(
							listConsumeAbility.get(i).getQuery_value2());
					axisNames.add(axisName);
					axisValues.add(axisValue);
					cnts += axisValue;
				}
			}
			Map consumeAbilitymap = new HashMap();
			consumeAbilitymap.put("axisNames", axisNames);
			consumeAbilitymap.put("axisValues", axisValues);
			consumeAbilitymap.put("cnts", cnts);
			JSONObject consumeAbilityJson = JSONObject
					.fromObject(consumeAbilitymap);

			// 4.游客来源分析
			List<CommonBaseBean> listProvCode = new ArrayList<CommonBaseBean>();
			try {
				listProvCode = this.getBaseDao().queryForList(
						NAMESPACE + "queryTourismProvCodeData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List axisProvs = new ArrayList();
			List axisProvValues = new ArrayList();
			int ProvCnts = 0;
			for (int i = 0; i < listProvCode.size(); i++) {
				int axisCntValue = Integer
						.parseInt(listProvCode.get(i).getQuery_value2());
				ProvCnts += axisCntValue;
			}
			for (int i = 0; i < listProvCode.size() && i < 5; i++) {
				String axisProv = listProvCode.get(i).getQuery_value1();
				int axisCntValue = Integer
						.parseInt(listProvCode.get(i).getQuery_value2());
				axisProvs.add(axisProv);
				axisProvValues.add(axisCntValue);
			}
			for (int i = 0; i < axisProvValues.size(); i++) {
				// double val=((double)axisValues.get(i))/cnts*100;
				// String percent=new
				// java.text.DecimalFormat("0.0").format(val);
				double db = (double) ((int) axisProvValues.get(i)) / cnts * 100;
				double percent = new BigDecimal(db)
						.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue(); // 四舍五入，保留1位小数
				axisProvValues.set(i, percent);

			}
			JSONArray axisProvsJson = JSONArray.fromObject(axisProvs);
			JSONArray axisProvValuesJson = JSONArray.fromObject(axisProvValues);

			// 5.手机品牌分析
			List<CommonBaseBean> listBrand = new ArrayList<CommonBaseBean>();
			try {
				listBrand = this.getBaseDao().queryForList(
						NAMESPACE + "queryTourismTermBrandData", map,
						CommonBaseBean.class);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}
			List<JSONObject> listBrandJson = new ArrayList<JSONObject>();
			List brandList = new ArrayList();
			int otherCnts = 0, num = 0;
			for (int i = 0; i < listBrand.size(); i++) {
				String brands = listBrand.get(i).getQuery_value1();
				String counts = listBrand.get(i).getQuery_value2();
				JSONObject tmpObj = new JSONObject();
				if (num < 8) {
					num++;
					tmpObj.put("name", brands);
					tmpObj.put("value", counts);
					listBrandJson.add(tmpObj);
					brandList.add(brands);
				} else {
					otherCnts += Integer.parseInt(counts);
				}
			}
			if (otherCnts != 0) {
				JSONObject othTmpObj = new JSONObject();
				othTmpObj.put("name", "其他");
				othTmpObj.put("value", String.valueOf(otherCnts));
				listBrandJson.add(othTmpObj);
				brandList.add("其他");
			}
			JSONArray brandListJson = JSONArray.fromObject(brandList);

			Map<String, Object> resultMap = new HashMap<String, Object>();
			resultMap.put("ageListData",
					null == ageJson ? "" : JsonUtil.Object2Json(ageJson));
			resultMap.put("genderListData",
					null == genderJson ? "" : JsonUtil.Object2Json(genderJson));
			resultMap.put("consumeAbilityData", null == consumeAbilityJson ? ""
					: JsonUtil.Object2Json(consumeAbilityJson));
			resultMap.put("axisProvsJson", null == axisProvsJson ? ""
					: JsonUtil.Object2Json(axisProvsJson));
			resultMap.put("axisProvValuesJson", null == axisProvValuesJson ? ""
					: JsonUtil.Object2Json(axisProvValuesJson));
			resultMap.put("termBrand", null == listBrandJson ? ""
					: JsonUtil.Object2Json(listBrandJson));
			resultMap.put("legend", null == brandListJson ? ""
					: JsonUtil.Object2Json(brandListJson));
			outputObject.setObject(JsonUtil.Object2Json(resultMap));
		}
	}

}
